<!--
 * @Date: 2022-04-24 11:39:42
 * @Author: 陶子
 * @LastEditTime: 2022-04-24 16:37:34
 * @FilePath: \jk_one-stop_cloud_mobile_v1.0\src\views\warehouseManagement\inventoryQuery\IMG.vue
 * @pageName: 这是--(图片组件)--页面
-->
<template>
  <div>
    <img class="goodLeft" v-if="pngUrl" :src="pngUrl" alt="" />
    <img class="goodLeft" v-else src="~@/assets/img/notPng.png" />
  </div>
</template>
<script>
import { apiBaseUrlDownload } from "@/utils/request";
import { getAction } from "@/api/manage";
export default {
  components: {},
  props: {
    attachment: {
      type: String,
      default: "",
    },
  },
  watch: {
    attachment(newVal, oldVal) {
      if (newVal) {
        let firstId = newVal.split(",")[0];
        let params = { id: firstId };
        getAction("/public/pubAttachmentFile/queryById", params).then((res) => {
          if (res.success) {
            let obj = res.result;
            this.pngUrl =
              this.apiBaseUrlDownload +
              "jksaas-mgt/mgt/sys/common/static/" +
              obj.uri;
          } else {
            this.pngUrl = "";
          }
        });
      }
    },
  },
  data() {
    return {
      apiBaseUrlDownload,
      pngUrl: "",
    };
  },
  created() {
    if (this.attachment) {
      let firstId = this.attachment.split(",")[0];
      let params = { id: firstId };
      getAction("/public/pubAttachmentFile/queryById", params).then((res) => {
        if (res.success) {
          let obj = res.result;
          this.pngUrl =
            this.apiBaseUrlDownload +
            "jksaas-mgt/mgt/sys/common/static/" +
            obj.uri;
        } else {
          this.pngUrl = "";
        }
      });
    }
  },
  methods: {},
};
</script>

<style scoped lang="less">
img.goodLeft {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 0.04rem;
}
</style>
